﻿@page "/counter"
@inject ISender _sender;

@using BlazorApp3.Client.Application.Features.Counter.Queries.GetCurrentCounter;
@using BlazorApp3.Client.Application.Features.Counter.Commands.IncreaseCounter;
@using BlazorApp3.Client.Application.Features.Counter.Commands.Reset;

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @_counter</p>

<button class="btn btn-primary" @onclick="IncrementCountAsync">Increase</button>
<button class="btn btn-primary" @onclick="ResetCounterAsync">Reset</button>
@code {
    private int _counter;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        _counter = await _sender.Send(new GetCurrentCounterQuery());
    }

    private async Task IncrementCountAsync()
    {
        _counter = await _sender.Send(new IncreaseCounterCommand());
    }

    private async Task ResetCounterAsync()
    {
        await _sender.Send(new ResetCounterCommand());
        _counter = 0;
    }
}
